package q812_largestTriangleArea;

public class Solution {
    /*
    此方法的本质是将三个点投影到x轴上
    可以形成三个梯形 通过计算几何的方式来解决该问题
     */
    public double largestTriangleArea(int[][] points) {
        int N = points.length;
        double res = 0;
        for (int i = 0; i < N - 2; i ++) {
            for (int j = i + 1; j < N - 1; j ++) {
                for (int k = j + 1; k < N; k ++) {
                    int[] point1 = points[i];
                    int[] point2 = points[j];
                    int[] point3 = points[k];
                    int x1 = point1[0], y1 = point1[1];
                    int x2 = point2[0], y2 = point2[1];
                    int x3 = point3[0], y3 = point3[1];
                    res = Math.max(res, 0.5 * Math.abs(x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)));
                }
            }
        }
        return res;

    }
}
